package com.dearbinge.utils;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 参数校验 非空
 *
 * @author wes
 * @date 2019/3/21
 */
public class BeanValidator {

    /**
     * 判断参数是否为空
     *
     * @param obj obj
     * @return 结果 false为空 true正常
     */
    @SafeVarargs
    public static Map<String, Object> checkParam(Map<String, Object>... obj) {
        Map<String, Object> returnMap = new HashMap<String, Object>(16);
        try {
            for (Map<String, Object> map : obj) {
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    Object value = entry.getValue();
                    if (StringUtils.isEmpty(value)) {
                        returnMap.put("name", entry.getKey());
                        returnMap.put("flag", false);
                        return returnMap;
                    }
                }
            }
            returnMap.put("flag", true);
        } catch (Exception e) {
            e.printStackTrace();
            returnMap.put("flag", false);
        }
        return returnMap;

    }

    /**
     * 校验标志
     */
    public static final String FLAG = "flag";


}
